package com.demo.permission.controller;


import com.demo.permission.service.IPermissionService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hxt
 * @since 2025-06-17
 */
@RestController
@RequestMapping("/permission")
@RequiredArgsConstructor
public class PermissionController {

    private final IPermissionService userRolesService;

    /**
     * 绑定默认角色
     * @param userId
     */
    @PutMapping("/bindDefaultRole")
    public void bindDefaultRole(Long userId){
        userRolesService.bindDefaultRole(userId);
    }

    /**
     * 获取用户角色编码
     * @param userId
     * @return
     */
    @GetMapping("/getUserRoleCode")
    public String getUserRoleCode(@RequestParam("userId") Long userId){
        return userRolesService.getUserRoleCode(userId);
    }

    /**
     * 升级为管理员
     * @param userId
     */
    @PutMapping("/upgradeToAdmin")
    public void upgradeToAdmin(@RequestParam("userId") Long userId){
        userRolesService.upgradeToAdmin(userId);
    }

    /**
     * 降级为普通用户
     * @param userId
     */
    @PutMapping("/downgradeToUser")
    public void downgradeToUser(@RequestParam("userId") Long userId){
        userRolesService.downgradeToUser(userId);
    }

    /**
     * 根据roleCode 获取用户id
     *  @param roleCodes
     *  @return
     */
    @GetMapping("/getUserIdByRoleCodes")
    public List<Long> getUserIdByRoleCodes(@RequestParam("roleCodes") List<String> roleCodes){
        return userRolesService.getUserIdByRoleCodes(roleCodes);
    }
}
